<?php
/**
 * Projekt_Action can be used to tie into some of the hooks
 * in Zend_Controller_Action
 *
 * @author Jim Harford
 *
 */

class Projekt_Action extends Zend_Controller_Action
{
    public function preDispatch ()
    {

        // Redirect to login if session does not exist
        if (! in_array($this->_getParam('controller'), array('index', 'error'))) {
            session_start();
            if (! isset($_SESSION['user_id'])) {
                $this->_redirect('/');
            }
        }

        $config = Zend_Registry::get('config');

        $db = Zend_Db::factory('Pdo_Mysql', array(
            'host' => $config['dbhost'],
            'username' => $config['dbusername'],
            'password' => $config['dbpassword'],
            'dbname' => $config['dbname']
        ));

        Zend_Db_Table_Abstract::setDefaultAdapter($db);


        //Set up menu
        if(isset($_SESSION['user_id'])){
	        require_once('../language/en.php');
	        Projekt_Html_Menu::setLang($pmlang['navigation']);

	        $menu = new AccessPageList();
	        $menuList = $menu->fetchAll();

	        $nav = new Projekt_Html_Menu($menuList, 'changeme');
	        $navHtml = $nav->render();

	        $this->view->navigation = $navHtml;
        }

    }

}